package com.aistar.mapper;

import com.aistar.model.entity.Delivery;
import org.apache.ibatis.annotations.*;
import org.springframework.boot.context.properties.bind.DefaultValue;

import java.util.List;

/**
 * @ClassName: DeliveryMapper
 * @author: LiuWenXiu
 * @date: 2021/9/27 14:40
 * @Description: TODO...
 */
public interface DeliveryMapper {

    // 根据职位id获取简历投递记录
    @Select("select * from delivery where recruitment_id = #{recruitmentId}")
    List<Delivery> findByRecruitmentId(Integer recruitmentId);

    @Select("select * from delivery where recruitment_id=#{recruitmentId} and status=#{status}")
    List<Delivery> findByRecruitmentAndStatus(@Param("recruitmentId") Integer recruitmentId, @Param("status") String status);

    // 修改简历投递状态
    @Update("update delivery set status = #{status} where id = #{id}")
    int updateStatusById(@Param("id") Integer id, @Param("status") String status);

    // 根据id获取简历投递记录
    @Select("select * from delivery where id = #{id}")
    Delivery findById(Integer id);

    // 根据id删除简历投递记录
    @Delete("delete from delivery where id = #{id}")
    int delDeliveryById(Integer id);

    //增加投递数据
    @Insert("insert into delivery(resume_id,recruitment_id,delivery_time,status) values(#{resumeId},#{recruitmentId},#{deliveryTime},#{status})")
    int save(Delivery delivery);

    @Select("select * from delivery where user_id = #{userId}")
    List<Delivery> findByUserId(Integer userId);

    @Select("select * from delivery where resume_id=#{resumeId}")
    List<Delivery> findByResumeId(Integer resumeId);

    //通过职位id和简历id确定信息
    @Select("select * from delivery where resume_id=#{resumeId} and recruitment_id=#{recruitmentId} ")
    List<Delivery> findByRidAndRsId(@Param("recruitmentId") Integer recruitmentId,@Param("resumeId") Integer resumeId);

    //通过求职者id和职位id获取投递次数
    @Select("select count(*) from delivery where employeeId=#{employeeId} and recruitmentId=#{recruitmentId}")
    Integer countDelivery(Integer employeeId,Integer recruitmentId);

    //根据简历id获取职位id
    @Select("select recruitment_id from delivery where resume_id=#{resumeId}")
    List<Delivery> findRecruitmentByResumeId(Integer resumeId);

    // 获取所有简历投递记录
    @Select("select * from delivery")
    List<Delivery> findAll();

    //根据求职者id

}
